
import threading
from typing import Any, List, Union
from aioredis import Redis
from redis import Redis
from fastapi import Header, Depends, Form, Request, APIRouter, File, UploadFile
from sqlalchemy.ext.asyncio import AsyncSession
from datasource.obtains import get_db_session, get_async_session, get_async_redis, get_sync_redis
from model import get_sync_db, SyncSession
from model.{{Lower .structName}} import {{.structName}}
from service import {{Lower .structName}}Srv

{{Lower .structName}}_rut = APIRouter(tags=[""])

{{- if eq .isUser true}}
@{{Lower .structName}}_rut.post("/{{Lower .structName}}/login", summary="用户登录认证")
async def sing(user_info: dict, session: AsyncSession = Depends(get_db_session)) -> Any:
    return await userSrv.login(session, user_info)
{{- end}}

@{{Lower .structName}}_rut.post("/{{Lower .structName}}/add")
async def add{{.structName}}(o: dict, session: AsyncSession = Depends(get_db_session)) -> dict:
    return await {{Lower .structName}}Srv.add_{{Lower .structName}}(session, o)

@{{Lower .structName}}_rut.put("/{{Lower .structName}}/update")
async def update{{.structName}}(o: dict, session: AsyncSession = Depends(get_db_session)) -> dict:
    return await {{Lower .structName}}Srv.update_{{Lower .structName}}(session, o)

@{{Lower .structName}}_rut.get("/{{Lower .structName}}/delete/{id}")
async def delete{{.structName}}(id: str, session: AsyncSession = Depends(get_db_session)) -> dict:
    return await {{Lower .structName}}Srv.delete_{{Lower .structName}}(session, id)

@{{Lower .structName}}_rut.get("/{{Lower .structName}}/findOne/{id}")
async def find{{.structName}}One(id: str, session: AsyncSession = Depends(get_db_session)) -> dict:
    result = await {{Lower .structName}}Srv.find_{{Lower .structName}}_one(session, id)

    return {"message": "查询成功", "code": 200, "data": result}

@{{Lower .structName}}_rut.put("/{{Lower .structName}}/findAll")
async def find{{.structName}}All(o: {{.structName}}, session: AsyncSession = Depends(get_db_session)) -> dict:
    pojos = await {{Lower .structName}}Srv.find_{{Lower .structName}}_all(session, o)

    return {"message": "查询成功", "code": 200, "data": pojos}

